﻿using ChinaAzureStorageRedirector.Properties;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Xml.Serialization;

namespace ChinaAzureStorageRedirector
{
    public class Helper
    {
        static public string RuleFilePath
        {
            get
            {
                string codeBase = Assembly.GetExecutingAssembly().CodeBase;
                UriBuilder uri = new UriBuilder(codeBase);
                string path = Uri.UnescapeDataString(uri.Path);
                return Path.GetDirectoryName(path) + Resources.RulesFileName;
            }
        }

        static public List<String> AllRules
        {
            get
            {

                XmlSerializer s = new XmlSerializer(typeof(List<String>));
                List<String> allRules;
                using (TextReader ReadFileStream = new StreamReader(Helper.RuleFilePath))
                {
                    allRules = (List<String>)s.Deserialize(ReadFileStream);
                }
                return allRules == null ? new List<String>() : allRules;
            }
        }
    }
}
